#include"mystdio.h"
#define MYFILE "log.txt"

int main()
{
     my_file * fp = myfopen(MYFILE, "w");
     if(fp==NULL)
     {
         perror("myfopen");
         exit(1);
     }
     //char ptr[10]="abcd";
     //myfwrite(ptr,1,strlen(ptr),fp);  
     
    int cnt = 2;
    while(cnt)
    {
      	char buf[1024];
   	    //int snprintf(char *str, size_t size, const char *format, ...);
        snprintf(buf,sizeof(buf),"%d\n",cnt--);//第二个参数是指定的dest的空间大小
        size_t size = myfwrite(buf,sizeof(char),strlen(buf),fp);
        printf("%lu\n",size);
       
        sleep(1);
    }
     myfclose(fp);

//      FILE * fp = fopen(MYFILE, "w");
//      if(fp==NULL)
//      {
//         perror("fopen");
//         exit(1);
//      }
//      int cnt = 3;
//      while(cnt)
//      {
//      	char buf[1024];
//    	   //int snprintf(char *str, size_t size, const char *format, ...);
//        snprintf(buf,sizeof(buf),"%d\n",cnt--);//第二个参数是指定的dest的空间大小
//        size_t size = fwrite(buf,sizeof(char),strlen(buf),fp);
//        printf("%lu\n",size);
      
//        sleep(1);
//      }
        return 0;
}